# 初始化
import os

import django

# 在environ字典里设置默认Django环境，'xxxx.settings'指Django项目的配置文件
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
django.setup()

from mysystem.models import Dept, Button, Menu, MenuButton, Role, Users


class Initialize:
    def __init__(self, delete=False):
        """
        delete 是否删除已初始化数据
        """
        self.delete = delete
        self.creator_id = "456b688c-8ad5-46de-bc2e-d41d8047bd42"

    def save(self, obj, data: list, name):
        print(f"正在初始化【{name}】")
        if self.delete:
            try:
                obj.objects.filter(id__in=[ele.get('id') for ele in data]).delete()
            except Exception:
                pass
        for ele in data:
            m2m_dict = {}
            new_data = {}
            for key, value in ele.items():
                # 判断传的 value 为 list 的多对多进行抽离，使用set 进行更新
                if isinstance(value, list):
                    m2m_dict[key] = value
                else:
                    new_data[key] = value
            object, _ = obj.objects.get_or_create(id=ele.get("id"), defaults=new_data)
            for key, m2m in m2m_dict.items():
                m2m = list(set(m2m))
                if m2m and len(m2m) > 0 and m2m[0]:
                    exec(f"""
if object.{key}:
    object.{key}.set({m2m})
""")
        print(f"初始化完成【{name}】")

    def init_dept(self):
        """
        初始化部门信息
        """
        self.dept_data = [
                        {
                            "id": "d2c03bd9-dad0-4262-88ca-c3681d224fc3",
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "update_datetime": "2024-04-13 09:34:19.651319",
                            "create_datetime": "2024-04-13 09:29:37.146050",
                            "name": "运维",
                            "sort": 1,
                            "status": "1",
                        },
                        {
                            "id": "a3b8e87b11004197b7b81ec454eb3535",
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "dept_belong_id": "d2c03bd9-dad0-4262-88ca-c3681d224fc3",
                            "update_datetime": "2024-04-13 09:34:25.593936",
                            "create_datetime": "2024-04-13 09:34:25.593936",
                            "name": "研发",
                            "sort": 0,
                            "status": "1",
                            "creator_id": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                        }
        ]
        self.save(Dept, self.dept_data, "部门信息")

    def init_button(self):
        """
        初始化权限表标识
        """
        self.button_data = [
            {"id": "4547b93a-36b9-410d-987c-3c52a9b51156", "name": "编辑", "value": "Update", },
            {"id": "4a410769-6b0a-4ed3-90f0-b5d89a6f802c", "name": "删除", "value": "Delete", },
            {"id": "644e9c34-e3d6-4518-b795-a603a6e9a137", "name": "单例", "value": "Retrieve", },
            {"id": "80cb145b-5035-4517-a28a-7d59426f73f8", "name": "新增", "value": "Create", },
            {"id": "ccc3f35f-c80c-4929-b8cc-67531698f397", "name": "查询", "value": "Search", },
            {"id": "83a9b774-4669-4d2f-b61d-8ee4944c2316", "name": "保存", "value": "Save", },
            {"id": "2d763a6d6dcf409d87056efd06aace0a", "name": "修改密码", "value": "Changepassword", },
            {"id": "6e0a41e5308c44a8b0d2785e05b2c07a", "name": "禁用", "value": "Disable", },
            {"id": "f3f365e9bfab44f587cbd91e3691ef0f", "name": "终端", "value": "Terminal", },
            {"id": "43d89c33967545a387a3ac27c02460b6", "name": "统计", "value": "Statistics", },
            {"id": "09134d7643504804a6c7cc3d16e06684", "name": "日志", "value": "Logs", },
            {"id": "5bf695439e9d4c4d9601bf4fb558b3a2", "name": "任务列表", "value": "Tasklist", },

        ]
        self.save(Button, self.button_data, "权限表标识")

    def init_menu(self):
        """
        初始化菜单表
        """
        self.menu_data = [
                        {
                            "id": "9065cb5445ac42ef93eb9e75e6287792",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.225838",
                            "create_datetime": "2024-04-13 09:29:37.225838",
                            "icon": "DataLine",
                            "name": "DashBoard",
                            "sort": 1,
                            "is_link": "0",
                            "web_path": "analysis",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": None
                        },
                        {
                            "id": "2e3438c8-3ddc-43ff-b8d8-cca328e4856e",
                            "description": None,
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:38:07.272918",
                            "create_datetime": "2024-04-13 09:29:37.231690",
                            "icon": "avatar",
                            "name": "用户管理",
                            "sort": 3,
                            "is_link": "0",
                            "web_path": "adminManage",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "23799b42974a49f8b0fab10f25b9c57b"
                        },
                        {
                            "id": "4236eb70-1558-43a0-9cf2-037230c547f9",
                            "description": None,
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:38:15.394295",
                            "create_datetime": "2024-04-13 09:29:37.270586",
                            "icon": "",
                            "name": "部门管理",
                            "sort": 1,
                            "is_link": "0",
                            "web_path": "departmentManage",
                            "component": "system/dept",
                            "component_name": "dept",
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "23799b42974a49f8b0fab10f25b9c57b"
                        },
                        {
                            "id": "4ba07859-8b73-4524-a1a6-bbff36d98337",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.274575",
                            "create_datetime": "2024-04-13 09:29:37.274575",
                            "icon": "",
                            "name": "操作日志",
                            "sort": 1,
                            "is_link": "0",
                            "web_path": "journalManage",
                            "component": "system/log/operationLog",
                            "component_name": "operationLog",
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "c236fb6b-ddaa-4deb-b79b-16e42d9f347f"
                        },
                        {
                            "id": "56c3f341-4f46-4b04-9cfc-c8a14701707e",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.280589",
                            "create_datetime": "2024-04-13 09:29:37.280589",
                            "icon": "",
                            "name": "菜单管理",
                            "sort": 2,
                            "is_link": "0",
                            "web_path": "menuManage",
                            "component": "system/menu",
                            "component_name": "menu",
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "54f769b0-3dff-416c-8102-e55ec44827cc"
                        },
                        {
                            "id": "e0f53902-e901-490c-83f3-331e60b97fcf",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.284548",
                            "create_datetime": "2024-04-13 09:29:37.284548",
                            "icon": "",
                            "name": "按钮配置",
                            "sort": 2,
                            "is_link": "0",
                            "web_path": "buttonConfig/:id/:name",
                            "component": "system/ menuButton",
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "0",
                            "creator_id": None,
                            "parent_id": "54f769b0-3dff-416c-8102-e55ec44827cc"
                        },
                        {
                            "id": "15c9ebc5-d12f-470a-a560-938a7dc57570",
                            "description": None,
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:37:59.773341",
                            "create_datetime": "2024-04-13 09:29:37.288537",
                            "icon": "",
                            "name": "角色管理",
                            "sort": 3,
                            "is_link": "0",
                            "web_path": "roleManage",
                            "component": "system/role",
                            "component_name": "role",
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "23799b42974a49f8b0fab10f25b9c57b"
                        },
                        {
                            "id": "a607e820-36e5-45c0-aabf-85a8e4e2c7ac",
                            "description": None,
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:37:54.047113",
                            "create_datetime": "2024-04-13 09:29:37.293524",
                            "icon": "",
                            "name": "权限管理",
                            "sort": 4,
                            "is_link": "0",
                            "web_path": "authorityManage",
                            "component": "system/rolePermission",
                            "component_name": "rolePermission",
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "23799b42974a49f8b0fab10f25b9c57b"
                        },
                        {
                            "id": "151035da-77a3-4a62-b474-fce6824571fb",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.299509",
                            "create_datetime": "2024-04-13 09:29:37.299509",
                            "icon": "",
                            "name": "按钮管理",
                            "sort": 6,
                            "is_link": "0",
                            "web_path": "buttonManage",
                            "component": "system/button",
                            "component_name": "buttonManage",
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "0",
                            "creator_id": None,
                            "parent_id": "54f769b0-3dff-416c-8102-e55ec44827cc"
                        },
                        {
                            "id": "54f769b0-3dff-416c-8102-e55ec44827cc",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.309395",
                            "create_datetime": "2024-04-13 09:29:37.309395",
                            "icon": "tools",
                            "name": "系统管理",
                            "sort": 990,
                            "is_link": "0",
                            "web_path": "",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": None
                        },
                        {
                            "id": "25735adb-d051-4b7b-bbb7-1154526f3e4c",
                            "description": None,
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:37:48.472344",
                            "create_datetime": "2024-04-13 09:29:37.314381",
                            "icon": "user",
                            "name": "个人中心",
                            "sort": 13,
                            "is_link": "0",
                            "web_path": "personalCenter",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "0",
                            "creator_id": None,
                            "parent_id": "23799b42974a49f8b0fab10f25b9c57b"
                        },
                        {
                            "id": "c236fb6b-ddaa-4deb-b79b-16e42d9f347f",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.318371",
                            "create_datetime": "2024-04-13 09:29:37.318371",
                            "icon": "info-filled",
                            "name": "日志管理",
                            "sort": 999,
                            "is_link": "0",
                            "web_path": "journalManage",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": None
                        },
                        {
                            "id": "77edf447326b4e0dbc6f9719c1de8a12",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.323358",
                            "create_datetime": "2024-04-13 09:29:37.323358",
                            "icon": "TrendCharts",
                            "name": "系统监控",
                            "sort": 888,
                            "is_link": "0",
                            "web_path": "",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": None
                        },
                        {
                            "id": "bcbeeee5c91a4e2ea2c2a31237e33616",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.327347",
                            "create_datetime": "2024-04-13 09:29:37.327347",
                            "icon": "",
                            "name": "服务监控",
                            "sort": 10,
                            "is_link": "0",
                            "web_path": "server",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "77edf447326b4e0dbc6f9719c1de8a12"
                        },
                        {
                            "id": "09a42810d4dd4b2eb939f8eb0b01d9d1",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.332336",
                            "create_datetime": "2024-04-13 09:29:37.332336",
                            "icon": "",
                            "name": "计划任务",
                            "sort": 20,
                            "is_link": "0",
                            "web_path": "crontab",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "77edf447326b4e0dbc6f9719c1de8a12"
                        },
                        {
                            "id": "718daec1b94b456c96d773889648173e",
                            "description": None,
                            "modifier": None,
                            "dept_belong_id": None,
                            "update_datetime": "2024-04-13 09:29:37.337321",
                            "create_datetime": "2024-04-13 09:29:37.337321",
                            "icon": "",
                            "name": "终端服务",
                            "sort": 30,
                            "is_link": "0",
                            "web_path": "terminal",
                            "component": None,
                            "component_name": None,
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": None,
                            "parent_id": "77edf447326b4e0dbc6f9719c1de8a12"
                        },
                        {
                            "id": "23799b42974a49f8b0fab10f25b9c57b",
                            "modifier": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                            "dept_belong_id": "d2c03bd9-dad0-4262-88ca-c3681d224fc3",
                            "update_datetime": "2024-04-13 09:37:38.193468",
                            "create_datetime": "2024-04-13 09:37:23.485498",
                            "icon": "User",
                            "name": "权限中心",
                            "sort": 995,
                            "is_link": "0",
                            "web_path": "",
                            "status": "1",
                            "isautopm": "0",
                            "cache": "0",
                            "visible": "1",
                            "creator_id": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
                        }
        ]
        self.save(Menu, self.menu_data, "菜单表")

    def init_menu_button(self):
        """
        初始化菜单权限表
        """
        self.menu_button_data = [

            {
                "id": "0209de89-6b9f-4d8a-84d3-ccfc3cc8b4da",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.386727",
                "create_datetime": "2024-04-13 09:29:37.386727",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/button/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "151035da-77a3-4a62-b474-fce6824571fb"
            },
            {
                "id": "04896a47-0f3a-4e2f-a111-bfe15f9e31c5",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.391714",
                "create_datetime": "2024-04-13 09:29:37.391714",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/menu/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "56c3f341-4f46-4b04-9cfc-c8a14701707e"
            },
            {
                "id": "3e11db64-b8e8-4558-963b-71d063a7db16",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.396701",
                "create_datetime": "2024-04-13 09:29:37.396701",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/dept/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "4236eb70-1558-43a0-9cf2-037230c547f9"
            },
            {
                "id": "5d77d14e-b199-481f-a97d-6e4c0e84fe71",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.400691",
                "create_datetime": "2024-04-13 09:29:37.400691",
                "name": "修改密码",
                "value": "Changepassword",
                "api": "/api/system/user/change_password/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "25735adb-d051-4b7b-bbb7-1154526f3e4c"
            },
            {
                "id": "bc114580-e62d-4e08-b707-843759817344",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.414652",
                "create_datetime": "2024-04-13 09:29:37.414652",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/user/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "2e3438c8-3ddc-43ff-b8d8-cca328e4856e"
            },
            {
                "id": "bc6104a0-f487-4dfd-a368-fb587d6d57d8",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.419639",
                "create_datetime": "2024-04-13 09:29:37.419639",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/menu_button/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "e0f53902-e901-490c-83f3-331e60b97fcf"
            },
            {
                "id": "d22c0176-96e0-48b3-b81e-13443f306af5",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.423628",
                "create_datetime": "2024-04-13 09:29:37.423628",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/role/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "15c9ebc5-d12f-470a-a560-938a7dc57570"
            },
            {
                "id": "dcc58831-08d1-4469-8b01-fca71e0f497f",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.427618",
                "create_datetime": "2024-04-13 09:29:37.427618",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/user/user_info/",
                "method": "2",
                "creator_id": None,
                "menu_id": "25735adb-d051-4b7b-bbb7-1154526f3e4c"
            },
            {
                "id": "e6b93920-2236-46ec-841b-cff6f63ce788",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.432605",
                "create_datetime": "2024-04-13 09:29:37.432605",
                "name": "编辑",
                "value": "Update",
                "api": "/api/system/operation_log/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "4ba07859-8b73-4524-a1a6-bbff36d98337"
            },
            {
                "id": "b4cbe8ed35a04155b14c7809fad6b2ef",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.441580",
                "create_datetime": "2024-04-13 09:29:37.441580",
                "name": "编辑",
                "value": "Update",
                "api": "/api/terminal/terminal/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "718daec1b94b456c96d773889648173e"
            },
            {
                "id": "140166e2-471e-455e-9dcd-05cebbbab95d",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.479480",
                "create_datetime": "2024-04-13 09:29:37.479480",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/role/",
                "method": "0",
                "creator_id": None,
                "menu_id": "15c9ebc5-d12f-470a-a560-938a7dc57570"
            },
            {
                "id": "324776a3-48ec-4bca-bdd9-1838e2b6f7cc",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.484466",
                "create_datetime": "2024-04-13 09:29:37.484466",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/user/",
                "method": "0",
                "creator_id": None,
                "menu_id": "2e3438c8-3ddc-43ff-b8d8-cca328e4856e"
            },
            {
                "id": "3688b715-4689-468f-bf3e-6f910259f837",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.489453",
                "create_datetime": "2024-04-13 09:29:37.489453",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/user/user_info/",
                "method": "0",
                "creator_id": None,
                "menu_id": "25735adb-d051-4b7b-bbb7-1154526f3e4c"
            },
            {
                "id": "37462e31-3cdf-4576-af10-5958f53b1bef",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.495437",
                "create_datetime": "2024-04-13 09:29:37.495437",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/operation_log/",
                "method": "0",
                "creator_id": None,
                "menu_id": "4ba07859-8b73-4524-a1a6-bbff36d98337"
            },
            {
                "id": "42ad6e05-7c84-444f-bcae-09de84f4988b",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.500424",
                "create_datetime": "2024-04-13 09:29:37.500424",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/menu/",
                "method": "0",
                "creator_id": None,
                "menu_id": "56c3f341-4f46-4b04-9cfc-c8a14701707e"
            },
            {
                "id": "5aac29b0-5a32-45fb-81c5-437b48f4a5df",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.514386",
                "create_datetime": "2024-04-13 09:29:37.514386",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/menu_button/",
                "method": "0",
                "creator_id": None,
                "menu_id": "e0f53902-e901-490c-83f3-331e60b97fcf"
            },
            {
                "id": "646e9790-24f5-4606-abc4-0b5eede12f66",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.519373",
                "create_datetime": "2024-04-13 09:29:37.519373",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/dept/",
                "method": "0",
                "creator_id": None,
                "menu_id": "4236eb70-1558-43a0-9cf2-037230c547f9"
            },
            {
                "id": "af60d628-73b1-4c5d-b34e-7c70ab9bd87e",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.524387",
                "create_datetime": "2024-04-13 09:29:37.524387",
                "name": "查询",
                "value": "Search",
                "api": "/api/system/button/",
                "method": "0",
                "creator_id": None,
                "menu_id": "151035da-77a3-4a62-b474-fce6824571fb"
            },
            {
                "id": "c2490dfba1644cae8f8ff85e2d6f1d3d",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.534332",
                "create_datetime": "2024-04-13 09:29:37.534332",
                "name": "查询",
                "value": "Search",
                "api": "",
                "method": "0",
                "creator_id": None,
                "menu_id": "9065cb5445ac42ef93eb9e75e6287792"
            },
            {
                "id": "a69fb746c0aa4bd0b31b1480c9e4dcc0",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.539319",
                "create_datetime": "2024-04-13 09:29:37.539319",
                "name": "查询",
                "value": "Search",
                "api": "/api/monitor/getsysteminfo/",
                "method": "0",
                "creator_id": None,
                "menu_id": "bcbeeee5c91a4e2ea2c2a31237e33616"
            },
            {
                "id": "e1ddf86666364a39be76c963c277b009",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.542946",
                "create_datetime": "2024-04-13 09:29:37.542946",
                "name": "查询",
                "value": "Search",
                "api": "/api/terminal/terminal/",
                "method": "0",
                "creator_id": None,
                "menu_id": "718daec1b94b456c96d773889648173e"
            },
            {
                "id": "4450d80871eb44a1aaa4fbb5429885f0",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.572868",
                "create_datetime": "2024-04-13 09:29:37.572868",
                "name": "查询",
                "value": "Search",
                "api": "/api/crontab/periodictask/",
                "method": "0",
                "creator_id": None,
                "menu_id": "09a42810d4dd4b2eb939f8eb0b01d9d1"
            },
            {
                "id": "0d931efc-2f80-418f-b4a0-5251f0a88f69",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.589823",
                "create_datetime": "2024-04-13 09:29:37.590821",
                "name": "新增",
                "value": "Create",
                "api": "/api/system/operation_log/",
                "method": "1",
                "creator_id": None,
                "menu_id": "4ba07859-8b73-4524-a1a6-bbff36d98337"
            },
            {
                "id": "10610c56-cec2-4774-9468-e1c763e59e70",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.594810",
                "create_datetime": "2024-04-13 09:29:37.594810",
                "name": "新增",
                "value": "Create",
                "api": "/api/system/dept/",
                "method": "1",
                "creator_id": None,
                "menu_id": "4236eb70-1558-43a0-9cf2-037230c547f9"
            },
            {
                "id": "1b4f27a7-8ab8-4388-ae57-46e29976cf0e",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.598799",
                "create_datetime": "2024-04-13 09:29:37.598799",
                "name": "新增",
                "value": "Create",
                "api": "/api/system/button/",
                "method": "1",
                "creator_id": None,
                "menu_id": "151035da-77a3-4a62-b474-fce6824571fb"
            },
            {
                "id": "2a3d4756-4d51-4129-b3c4-b2c7a00dbb8a",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.602788",
                "create_datetime": "2024-04-13 09:29:37.602788",
                "name": "新增",
                "value": "Create",
                "api": "/api/system/role/",
                "method": "1",
                "creator_id": None,
                "menu_id": "15c9ebc5-d12f-470a-a560-938a7dc57570"
            },
            {
                "id": "9e6b2376-1ab0-4966-8d5d-4ad4f911d13c",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.606779",
                "create_datetime": "2024-04-13 09:29:37.606779",
                "name": "新增",
                "value": "Create",
                "api": "/api/system/user/",
                "method": "1",
                "creator_id": None,
                "menu_id": "2e3438c8-3ddc-43ff-b8d8-cca328e4856e"
            },
            {
                "id": "abe5c07f-0cab-4053-ac24-e782792e9d7f",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.619743",
                "create_datetime": "2024-04-13 09:29:37.619743",
                "name": "新增",
                "value": "Create",
                "api": "/api/system/menu/",
                "method": "1",
                "creator_id": None,
                "menu_id": "56c3f341-4f46-4b04-9cfc-c8a14701707e"
            },
            {
                "id": "fc71b446-fde1-439f-ab41-c38f30230caa",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.623732",
                "create_datetime": "2024-04-13 09:29:37.623732",
                "name": "新增",
                "value": "Create",
                "api": "/api/system/menu_button/",
                "method": "1",
                "creator_id": None,
                "menu_id": "e0f53902-e901-490c-83f3-331e60b97fcf"
            },
            {
                "id": "8d65733d401c40f8b27cc6bcfed78bc3",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.631711",
                "create_datetime": "2024-04-13 09:29:37.631711",
                "name": "新增",
                "value": "Create",
                "api": "/api/terminal/terminal/",
                "method": "1",
                "creator_id": None,
                "menu_id": "718daec1b94b456c96d773889648173e"
            },
            {
                "id": "19d01a929bc9414cac1a8defd48597c9",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.648666",
                "create_datetime": "2024-04-13 09:29:37.648666",
                "name": "新增",
                "value": "Create",
                "api": "/api/crontab/periodictask/",
                "method": "1",
                "creator_id": None,
                "menu_id": "09a42810d4dd4b2eb939f8eb0b01d9d1"
            },
            {
                "id": "6208f412-6bca-4d7b-a5a0-0103b7ba6091",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.675593",
                "create_datetime": "2024-04-13 09:29:37.675593",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/button/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "151035da-77a3-4a62-b474-fce6824571fb"
            },
            {
                "id": "6300774a-d19c-43ad-8102-d7bf341eff33",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.679583",
                "create_datetime": "2024-04-13 09:29:37.679583",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/dept/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "4236eb70-1558-43a0-9cf2-037230c547f9"
            },
            {
                "id": "8b7a0e79-a6ef-4946-87c6-8c042b887e1c",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.684570",
                "create_datetime": "2024-04-13 09:29:37.684570",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/operation_log/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "4ba07859-8b73-4524-a1a6-bbff36d98337"
            },
            {
                "id": "96022ae5-6425-47b9-8f89-01edc33eb2b7",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.688559",
                "create_datetime": "2024-04-13 09:29:37.688559",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/role/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "15c9ebc5-d12f-470a-a560-938a7dc57570"
            },
            {
                "id": "f0e080c0-275d-4085-b56c-735b49510eff",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.693546",
                "create_datetime": "2024-04-13 09:29:37.693546",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/user/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "2e3438c8-3ddc-43ff-b8d8-cca328e4856e"
            },
            {
                "id": "fcbe4cec-cc2d-436d-92ba-023f8c9ad31c",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.697535",
                "create_datetime": "2024-04-13 09:29:37.697535",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/menu/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "56c3f341-4f46-4b04-9cfc-c8a14701707e"
            },
            {
                "id": "fe96f32c-6124-4b24-b809-4964186f5163",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.701525",
                "create_datetime": "2024-04-13 09:29:37.701525",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/menu_button/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "e0f53902-e901-490c-83f3-331e60b97fcf"
            },
            {
                "id": "6d6b6689d1224900b09c8101b3344f42",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.709503",
                "create_datetime": "2024-04-13 09:29:37.709503",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/system/role_id_to_menu/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "a607e820-36e5-45c0-aabf-85a8e4e2c7ac"
            },
            {
                "id": "f19826f7df9842089cee94a795681b2e",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.714491",
                "create_datetime": "2024-04-13 09:29:37.714491",
                "name": "单例",
                "value": "Retrieve",
                "api": "",
                "method": "0",
                "creator_id": None,
                "menu_id": "9065cb5445ac42ef93eb9e75e6287792"
            },
            {
                "id": "ea18bb51400b482a8aad5dc18357bcab",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.718479",
                "create_datetime": "2024-04-13 09:29:37.718479",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/terminal/terminal/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "718daec1b94b456c96d773889648173e"
            },
            {
                "id": "6e27757847c64e228934b60ae81baedf",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.749396",
                "create_datetime": "2024-04-13 09:29:37.749396",
                "name": "单例",
                "value": "Retrieve",
                "api": "/api/crontab/periodictask/{id}/",
                "method": "0",
                "creator_id": None,
                "menu_id": "09a42810d4dd4b2eb939f8eb0b01d9d1"
            },
            {
                "id": "2c53efc8-e6a4-4192-8688-03baed0874a4",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.766352",
                "create_datetime": "2024-04-13 09:29:37.766352",
                "name": "删除",
                "value": "Delete",
                "api": "/api/system/user/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "2e3438c8-3ddc-43ff-b8d8-cca328e4856e"
            },
            {
                "id": "3fd6ae6c-fd76-4465-b2b6-db672f4bd79e",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.770341",
                "create_datetime": "2024-04-13 09:29:37.770341",
                "name": "删除",
                "value": "Delete",
                "api": "/api/system/role/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "15c9ebc5-d12f-470a-a560-938a7dc57570"
            },
            {
                "id": "4fe4b7f5-0bc8-4375-9f39-747e06ec285a",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.774330",
                "create_datetime": "2024-04-13 09:29:37.774330",
                "name": "删除",
                "value": "Delete",
                "api": "/api/system/menu_button/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "e0f53902-e901-490c-83f3-331e60b97fcf"
            },
            {
                "id": "51085c21-2279-490f-8878-594f059f7616",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.778321",
                "create_datetime": "2024-04-13 09:29:37.778321",
                "name": "删除",
                "value": "Delete",
                "api": "/api/system/button/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "151035da-77a3-4a62-b474-fce6824571fb"
            },
            {
                "id": "8ae924bd-576c-4ae1-92eb-b0a98148baae",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.783306",
                "create_datetime": "2024-04-13 09:29:37.783306",
                "name": "删除",
                "value": "Delete",
                "api": "/api/system/menu/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "56c3f341-4f46-4b04-9cfc-c8a14701707e"
            },
            {
                "id": "acfde861-1872-47e2-a1f1-abeda5175b7f",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.787295",
                "create_datetime": "2024-04-13 09:29:37.787295",
                "name": "删除",
                "value": "Delete",
                "api": "/api/system/operation_log/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "4ba07859-8b73-4524-a1a6-bbff36d98337"
            },
            {
                "id": "b10f7d08-2592-4b54-8557-b5ca864a029a",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.791285",
                "create_datetime": "2024-04-13 09:29:37.791285",
                "name": "删除",
                "value": "Delete",
                "api": "/api/system/dept/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "4236eb70-1558-43a0-9cf2-037230c547f9"
            },
            {
                "id": "281ad1aad421441a965f7bc6b397eb30",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.807241",
                "create_datetime": "2024-04-13 09:29:37.807241",
                "name": "删除",
                "value": "Delete",
                "api": "/api/terminal/terminal/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "718daec1b94b456c96d773889648173e"
            },
            {
                "id": "576008b6046f4afcb88d8139ff34e228",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.838159",
                "create_datetime": "2024-04-13 09:29:37.838159",
                "name": "删除",
                "value": "Delete",
                "api": "/api/crontab/periodictask/{id}/",
                "method": "3",
                "creator_id": None,
                "menu_id": "09a42810d4dd4b2eb939f8eb0b01d9d1"
            },
            {
                "id": "1a0c96cf-09a6-43b4-b08a-0c5b6e2f7bb8",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.846138",
                "create_datetime": "2024-04-13 09:29:37.846138",
                "name": "保存",
                "value": "Save",
                "api": "/api/system/permission/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "a607e820-36e5-45c0-aabf-85a8e4e2c7ac"
            },
            {
                "id": "0ce04d99cbd249a9af88fe1496591a89",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.868079",
                "create_datetime": "2024-04-13 09:29:37.868079",
                "name": "禁用",
                "value": "Disable",
                "api": "/api/crontab/periodictask/enabled/{id}/",
                "method": "2",
                "creator_id": None,
                "menu_id": "09a42810d4dd4b2eb939f8eb0b01d9d1"
            },
            {
                "id": "6af0929440a345238c28ee9b1fe341ba",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.872069",
                "create_datetime": "2024-04-13 09:29:37.872069",
                "name": "终端",
                "value": "Terminal",
                "api": "/ws/webssh/",
                "method": "5",
                "creator_id": None,
                "menu_id": "718daec1b94b456c96d773889648173e"
            },
            {
                "id": "0b5bf0f1caac45beabf54fb5d930187b",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.889023",
                "create_datetime": "2024-04-13 09:29:37.889023",
                "name": "日志",
                "value": "Logs",
                "api": "/api/crontab/taskresult/",
                "method": "0",
                "creator_id": None,
                "menu_id": "09a42810d4dd4b2eb939f8eb0b01d9d1"
            },
            {
                "id": "fa8d945124b74379aba32bcf34ea5383",
                "description": None,
                "modifier": None,
                "dept_belong_id": None,
                "update_datetime": "2024-04-13 09:29:37.894009",
                "create_datetime": "2024-04-13 09:29:37.894009",
                "name": "任务列表",
                "value": "Search",
                "api": "/api/crontab/periodictask/tasklist/",
                "method": "0",
                "creator_id": None,
                "menu_id": "09a42810d4dd4b2eb939f8eb0b01d9d1"
            }
        ]
        self.save(MenuButton, self.menu_button_data, "菜单权限表")

    def init_role(self):
        """
        初始化角色表
        """
        data = [
            {"id": "36001d1a-1b3e-4413-bdfe-b3bc04375f46", "name": "管理员", "key": "admin", "sort": 1, "status": 1,
             "admin": 1, "data_range": 3,
             "menu": [ele.get("id") for ele in self.menu_data],
             "permission": [ele.get("id") for ele in self.menu_button_data]
             },
            {"id": "35b58d98-b506-4f93-be79-ed1e109da071", "name": "普通用户", "key": "public", "sort": 2, "status": 1,
             "admin": 0, "data_range": 4,
             "dept": ["d2c03bd9-dad0-4262-88ca-c3681d224fc3", "fd8230ca-67bd-4347-8a9b-57eb19be5d9e"],
             "menu": ["15c9ebc5-d12f-470a-a560-938a7dc57570", "4236eb70-1558-43a0-9cf2-037230c547f9",
                      "54f769b0-3dff-416c-8102-e55ec44827cc", "56c3f341-4f46-4b04-9cfc-c8a14701707e",
                      "244b28685cd14a39a383189981510d4a"],
             "permission": []
             },
            #自定义


        ]
        self.save(Role, data, "角色表")

    def init_users(self):
        """
        初始化用户表
        """
        data = [
            {"id": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
             "password": "pbkdf2_sha256$260000$oE0tnjC7PRIV6aCEah0J1F$scZo6l2/kekoClW8jZ6bM4PmSXevb4qzqHLro8PvzLc=",
             "is_superuser": 1, "is_staff": 1,"identity":0,
             "is_active": 1, "username": "superadmin", "name": "超级管理员",
             "dept_id": "d2c03bd9-dad0-4262-88ca-c3681d224fc3",
             },
            {"id": "d1431450-5068-4461-b57e-7862c005a547",
             "password": "pbkdf2_sha256$260000$DO6dpT8e4Ls0yD51grncC8$KZfswxNJ8MILTWwy+bicRyU7Q3PKC4orn4SJbhIkN4Q=",
             "is_superuser": 0, "is_staff": 1,"identity":1,
             "is_active": 1, "username": "admin", "name": "管理员",
             "dept_id": "d2c03bd9-dad0-4262-88ca-c3681d224fc3",
             "role": ["36001d1a-1b3e-4413-bdfe-b3bc04375f46"],
             },
        ]
        self.save(Users, data, "用户表")

    def run(self):
        self.init_dept()
        self.init_button()
        self.init_menu()
        self.init_menu_button()
        self.init_role()
        self.init_users()



def main(is_delete=False):
    Initialize(is_delete).run()
    pass


if __name__ == '__main__':
    print("1")
    main()
